package com.tx.studentManager.dao;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.tx.studentManager.dao.base.HibernateGenericDao;
import com.tx.studentManager.model.StudentClass;
import com.tx.studentManager.qo.StudentClassQO;


@Repository
public class StudentClassDao extends
		HibernateGenericDao<StudentClass, String, StudentClassQO> {

	@Override
	protected Criteria buildCriteria(Criteria criteria, StudentClassQO qo) {
		//指定了专业，院系就没有意义了
		if (StringUtils.isNotBlank(qo.getMajorId())) {
			qo.setDepId(null);
		}
		if (StringUtils.isNotBlank(qo.getMajorId())) {
			criteria.createCriteria("major").add(Restrictions.eq("majorId", qo.getMajorId()));
		}
		if (StringUtils.isNotBlank(qo.getDepId())) {
			criteria.createCriteria("major").createCriteria("department").add(Restrictions.eq("depId", qo.getDepId()));
		}
		return criteria;
	}
}
